
***************************************************************************
* Are Consumers' Spending Decisions in Line With an Euler Equation?
* Lena Dräger and Giang Nghiem
* February 2020
**************************************************************************
* This do-file performs the estimations using the Hamburg survey in the main paper
**************************************************************************

clear

use "Hamburg_Survey_Data_selected.dta", clear

// Set panel dimension

xtset hh_id wave

/// Figures

bysort infl_exp_qual: egen m_infl_exp = mean(infl_exp_quant)  if  abs(infl_exp_quant) <=15 

bysort infl_perc_qual: egen m_infl_perc = mean(infl_perc_quant)  if  abs(infl_perc_quant) <=15 

bysort int_exp_qual: egen m_int_exp = mean(int_exp_quant) if int_exp_quant <=5 & wave ==1 

bysort infl_perc_qual: egen mexp_infl_perc = mean(infl_exp_quant)  if  abs(infl_exp_quant) <=15 

**Figure 1: Inflation Perceptions and Expectations 

*Figure 1a
 hist infl_exp_quant if abs(infl_exp_quant) <=15 , discrete frequency  ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Quantitative Inflation Expectations ") name(hist_infl_exp_quant, replace)
 save hist_infl_exp_quant, replace
 
*Figure 1b

 hist infl_perc_quant if abs(infl_perc_quant) <=15 , discrete frequency  ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Quantitative Inflation Expectations ") name(hist_infl_perc_quant, replace)
 save hist_infl_perc_quant
 

*Figure 1c
 twoway (lfitci infl_exp_quant infl_perc_quant) (scatter infl_exp_quant infl_perc_quant) if  abs(infl_exp_quant) <=15 &  abs(infl_perc_quant) <=15, ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Quantitative inflation perceptions") ytitle("Quantitative inflation expectations") name(infl_exp_perc_quant, replace)
 save infl_exp_perc_quant

*Figure 1d
 gen infl_exp_detrend = infl_exp_quant - infl_perc_quant

 hist infl_exp_detrend if abs(infl_exp_detrend) <=15 , discrete frequency  ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Quantitative Inflation Expectations Corrected for Perceptions") name(hist_infl_exp_quant_detrend, replace)
 graph export hist_infl_exp_quant_detrend
 
 
*Figure 2: Quantitative vs. Qualitative Inflation Expectations

*Figure 2a
 sort infl_exp_qual

 twoway (scatter infl_exp_quant infl_exp_qual)  (line m_infl_exp infl_exp_qual ) if  abs(infl_exp_quant) <=15, ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Qualitative inflation expectations") ytitle("Quantitative inflation expectations") legend(off) name(infl_exp_quant_qual, replace)
 save infl_exp_quant_qual


*Figure 2b
 sort infl_perc_qual

 twoway (scatter infl_perc_quant infl_perc_qual) (line m_infl_perc infl_perc_qual)  if  abs(infl_perc_quant) <=15, ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Qualitative inflation perceptions") ytitle("Quantitative inflation perceptions") legend(off) name(infl_perc_quant_qual, replace)
 graph export infl_perc_quant_qual

*Figure 2c
 sort infl_perc_qual
 twoway (scatter infl_exp_quant infl_perc_qual) (line mexp_infl_perc infl_perc_qual)  if  abs(infl_exp_quant) <=15 , ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Qualitative inflation perceptions") ytitle("Quantitative inflation expectations") legend(off) name(infl_exp_quant_perc_qual, replace)
 graph export infl_exp_quant_perc_qual


**Figure 3: Interest rate expectations 

*Figure 3a

 hist int_exp_quant if int_exp_quant <=5  & wave ==1, discrete frequency  ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Quantitative Interest Rate Expectations ") name(hist_int_exp_quant, replace)
 graph export hist_int_exp_quant

*Figure 3b

 sort int_exp_qual

 twoway (scatter int_exp_quant int_exp_qual)  (line m_int_exp int_exp_qual ) if  int_exp_quant <=5 & wave ==1, ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Qualitative interest rate expectations") ytitle("Quantitative interest rate expectations") legend(off) name(int_exp_quant_qual, replace)
 graph export int_exp_quant_qual


*Figure 3c
 twoway (lfitci infl_exp_quant int_exp_quant) (scatter infl_exp_quant int_exp_quant) if  abs(infl_exp_quant) <=15 & int_exp_quant <=5 & wave ==1 , ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Qualitative interest rate expectations") ytitle("Quantitative inflation expectations") name(infl_exp_quant_int_exp_quant, replace)
 graph export infl_exp_quant_int_exp_quant


*Figure 3d
 twoway (lfitci infl_perc_quant int_exp_quant) (scatter infl_perc_quant int_exp_quant) if  abs(infl_perc_quant) <=15 & int_exp_quant <=5 & wave ==1 , ///
 graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) ///
 xtitle("Qualitative interest rate expectations") ytitle("Quantitative inflation perceptions") name(infl_perc_quant_int_exp_quant, replace)
 graph export infl_perc_quant_int_exp_quant


************************************************************************************
************************************************************************************

*Estimations

 global demo1 sex age age2 inc_l inc_ml inc_mh edu_h edu_m retired employ_ml employ_mh employ_h risk econ_exp_qual unemp_exp_qual wave
 
*Table 1: Consumption Euler Equation

	estimate clear

qui: oprobit cons_past cons_fut int_exp_qual infl_exp_qual $demo1 [pweight=weight] , vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_qual) predict(outcome(3)) atmean 

qui: oprobit cons_past cons_fut int_exp_qual infl_exp_quant $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 , vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_quant) predict(outcome(3)) atmean 

qui: oprobit cons_past cons_fut int_exp_qual infl_exp_qual $demo1 [pweight=weight] if basic_literacy==1, vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_qual) predict(outcome(3)) atmean 

qui: oprobit cons_past cons_fut int_exp_quant infl_exp_quant $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & wave ==1 & int_exp_quant <=5, vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_quant infl_exp_quant) predict(outcome(3)) atmean 

qui: oprobit cons_past cons_fut int_exp_qual infl_exp_quant $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & basic_literacy==1, vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_quant) predict(outcome(3)) atmean 

qui: oprobit cons_past cons_fut int_exp_quant infl_exp_quant $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & basic_literacy==1 & wave ==1 & int_exp_quant <=5, vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_quant infl_exp_quant) predict(outcome(3)) atmean 

*******************************************************************************************************************************************************************************************
*Table 2: Euler Equation with the Readiness to Spend on Durables

qui: oprobit climate_cons cons_durfut int_exp_qual infl_exp_qual $demo1 [pweight=weight] , vce(cluster hh_id)
estpost margins, dydx(cons_durfut int_exp_qual infl_exp_qual) predict(outcome(3)) atmean 

qui: oprobit climate_cons cons_durfut int_exp_qual infl_exp_quant $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 , vce(cluster hh_id)
estpost margins, dydx(cons_durfut int_exp_qual infl_exp_quant) predict(outcome(3)) atmean 

qui: oprobit climate_cons cons_durfut int_exp_quant infl_exp_quant $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & wave ==1 & int_exp_quant <=5, vce(cluster hh_id)
estpost margins, dydx(cons_durfut int_exp_quant infl_exp_quant) predict(outcome(3)) atmean 

qui: oprobit climate_cons cons_durfut int_exp_qual infl_exp_qual $demo1 [pweight=weight] if basic_literacy==1, vce(cluster hh_id)
estpost margins, dydx(cons_durfut int_exp_qual infl_exp_qual) predict(outcome(3)) atmean 

qui: oprobit climate_cons cons_durfut int_exp_qual infl_exp_quant $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & basic_literacy==1, vce(cluster hh_id)
estpost margins, dydx(cons_durfut int_exp_qual infl_exp_quant) predict(outcome(3)) atmean 

qui: oprobit climate_cons cons_durfut int_exp_quant infl_exp_quant $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & basic_literacy==1 & wave ==1 & int_exp_quant <=5, vce(cluster hh_id)
estpost margins, dydx(cons_durfut int_exp_quant infl_exp_quant) predict(outcome(3)) atmean 

*********************************************************************************************************************************************************************************************
*Table 3: Consumption Euler Equation: Using Inflation Perceptions as Instruments for Inflation Expectations

estimate clear

qui: reg infl_exp_qual infl_perc_qual cons_fut int_exp_qual $demo1 [pweight=weight] , vce(cluster hh_id) 
te infl_perc_qual
predict uhat, resid
qui: oprobit cons_past cons_fut int_exp_qual infl_exp_qual uhat $demo1  [pweight=weight]  , vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_qual) predict(outcome(3)) atmean 
drop uhat


qui: reg  infl_exp_quant infl_perc_quant cons_fut int_exp_qual  $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & abs(infl_perc_quant)<=15 , vce(cluster hh_id) 
te infl_perc_quant
predict uhat, resid
qui: oprobit cons_past cons_fut int_exp_qual infl_exp_quant uhat $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & abs(infl_perc_quant)<=15 , vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_quant) predict(outcome(3)) atmean 
drop uhat


qui: reg infl_exp_qual infl_perc_qual cons_fut int_exp_qual  $demo1 [pweight=weight] if basic_literacy==1, vce(cluster hh_id) 
te infl_perc_qual
predict uhat, resid
qui: oprobit cons_past cons_fut int_exp_qual infl_exp_qual uhat $demo1  [pweight=weight] if basic_literacy==1 , vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_qual) predict(outcome(3)) atmean 
drop uhat


qui: reg infl_exp_quant infl_perc_quant cons_fut int_exp_qual  $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & abs(infl_perc_quant)<=15 & basic_literacy==1 , vce(cluster hh_id) 
te infl_perc_quant
predict uhat, resid
qui: oprobit cons_past cons_fut int_exp_qual infl_exp_quant uhat $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & abs(infl_perc_quant)<=15 & basic_literacy==1, vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_quant) predict(outcome(3)) atmean 
drop uhat

*****************************************************************************************************************************************************************************************
*Table 4: Consumption Euler Equation: Multiple Measurement IV Approach

estimate clear

qui: reg infl_exp_qual infl_exp_quant cons_fut int_exp_qual  $demo1 [pweight=weight] if abs(infl_exp_quant)<=15, vce(cluster hh_id) 
te infl_exp_quant
predict uhat, resid
qui: oprobit cons_past cons_fut int_exp_qual infl_exp_qual uhat $demo1 [pweight=weight]  if abs(infl_exp_quant)<=15, vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_qual) predict(outcome(3)) atmean 
drop uhat


qui: reg  infl_exp_quant infl_exp_qual cons_fut int_exp_qual  $demo1 [pweight=weight] if abs(infl_exp_quant)<=15  , vce(cluster hh_id) 
te infl_exp_qual
predict uhat, resid
qui: oprobit cons_past cons_fut int_exp_qual infl_exp_quant uhat $demo1 [pweight=weight] if abs(infl_exp_quant)<=15  , vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_quant) predict(outcome(3)) atmean 
drop uhat


qui: reg infl_exp_qual infl_exp_quant cons_fut int_exp_qual  $demo1 [pweight=weight] if abs(infl_exp_quant)<=15 & basic_literacy==1, vce(cluster hh_id) 
te infl_exp_quant 
predict uhat, resid
qui: oprobit cons_past cons_fut int_exp_qual infl_exp_qual uhat $demo1  [pweight=weight] if abs(infl_exp_quant)<=15 & basic_literacy==1 , vce(cluster hh_id)
estpost margins, dydx(cons_fut int_exp_qual infl_exp_qual) predict(outcome(3)) atmean 
drop uhat


qui: reg infl_exp_quant infl_exp_qual cons_fut int_exp_qual $demo1 [pweight=weight] if abs(infl_exp_quant)<=15  & basic_literacy==1 , vce(cluster hh_id) 
te infl_exp_qual
predict uhat, resid
qui: oprobit cons_past  cons_fut  int_exp_qual infl_exp_quant uhat $demo1 [pweight=weight] if abs(infl_exp_quant)<=15  & basic_literacy==1, vce(cluster hh_id)
estpost margins, dydx(cons_fut  int_exp_qual infl_exp_quant uhat) predict(outcome(3)) atmean 
drop uhat

****************************************************************************************************************************************************************

*Figure 4: News Effects

local news	"news_monetary news_finance"
foreach x of local news {
local y : variable label `x'
	qui: oprobit cons_past cons_fut c.int_exp_qual##i.`x' c.infl_exp_qual##i.`x' $demo1 [pweight=weight], vce(cluster hh_id)
	qui: margins `x' , dydx(infl_exp_qual) predict(outcome(3)) 
	marginsplot, level(90) ytitle("") xtitle("`y'")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title("Marginal Effect of Inflation Expectation with 90% CIs")
	graph export inflexp_`x'.pdf, as(pdf) replace
		}
		
local news	"news_monetary news_finance"
foreach x of local news {
local y : variable label `x'
	qui: oprobit cons_past cons_fut c.int_exp_qual##i.`x' c.infl_exp_qual##i.`x' $demo1 [pweight=weight], vce(cluster hh_id)
	qui: margins `x' , dydx(int_exp_qual) predict(outcome(3)) 
	marginsplot, level(90) ytitle("") xtitle("`y'")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title("Marginal Effect of Interest Rate Expectation with 90% CIs")
	graph export intexp_`x'.pdf, as(pdf) replace	
		}
************************************************************************************************************************************************************************************************************************************************************************

*Figure 5: News and Heterogeneity Across Socio-Demographic Groups
estimate clear

global demo1 sex age age2 inc_l inc_ml inc_mh edu_h edu_m retired employ_ml employ_mh employ_h risk econ_exp_qual unemp_exp_qual wave

set more off

*Figure 5a, 5b: Non-savers vs. Saver 

*Financial news

qui: oprobit cons_past cons_fut i.news_finance##c.int_exp_qual##i.saver2 i.news_finance##c.infl_exp_qual##i.saver2 $demo1 [pweight=weight], vce(cluster hh_id)
qui: margins news_finance, dydx(int_exp_qual) predict(outcome(3)) by(saver2)
marginsplot, by(saver2) level(90) ytitle("") xtitle("Financial news")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title(" ") 
graph save saver2_intexp_news_finance, replace

*Monetary news

qui: oprobit cons_past cons_fut i.news_monetary##c.int_exp_qual##i.saver2 i.news_monetary##c.infl_exp_qual##i.saver2 $demo1 [pweight=weight], vce(cluster hh_id)
qui: margins news_monetary, dydx(infl_exp_qual) predict(outcome(3)) by(saver2)
marginsplot, by(saver2) level(90) ytitle("") xtitle("Monetary news")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title(" ") 
graph save saver2_inflexp_news_mp, replace


* Figure 5c, 5d: Low vs. High Financial literacy

*Finance news

qui: oprobit cons_past cons_fut i.news_finance##c.int_exp_qual##i.basic_literacy i.news_finance##c.infl_exp_qual##i.basic_literacy $demo1 [pweight=weight], vce(cluster hh_id)
qui: margins news_finance, dydx(int_exp_qual) predict(outcome(3)) by(basic_literacy)
marginsplot, by(basic_literacy) level(90) ytitle("") xtitle("Financial news")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title(" ") 
graph save literacy_intexp_news_finance, replace

*Monetary news

qui: oprobit cons_past cons_fut i.news_monetary##c.int_exp_qual##i.basic_literacy i.news_monetary##c.infl_exp_qual##i.basic_literacy $demo1 [pweight=weight], vce(cluster hh_id)
qui: margins news_monetary, dydx(infl_exp_qual) predict(outcome(3)) by(basic_literacy)
marginsplot, by(basic_literacy) level(90) ytitle("") xtitle("Monetary news")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title(" ") 
graph save literacy_inflexp_news_mp, replace

*Figure 5e, 5f: Young vs. Old

*Finance news
qui: oprobit cons_past cons_fut i.news_finance##c.int_exp_qual##i.age_group2 i.news_finance##c.infl_exp_qual##i.age_group2 $demo1 [pweight=weight], vce(cluster hh_id)
qui: margins news_finance, dydx(int_exp_qual) predict(outcome(3)) by(age_group2)
marginsplot, by(age_group2) level(90) ytitle("") xtitle("Financial news")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title(" ") 
graph save age_group2_intexp_news_finance, replace

*Monetary news

qui: oprobit cons_past cons_fut i.news_monetary##c.int_exp_qual##i.age_group2 i.news_monetary##c.infl_exp_qual##i.age_group2 $demo1 [pweight=weight], vce(cluster hh_id)
qui: margins news_monetary, dydx(infl_exp_qual) predict(outcome(3)) by(age_group2)
marginsplot, by(age_group2) level(90) ytitle("") xtitle("Monetary news")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title(" ") 
graph save age_group2_inflexp_news_mp, replace


**Figure 5g, 5h: Low vs. High Education

*Finance news
qui: oprobit cons_past cons_fut i.news_finance##c.int_exp_qual##i.edu_h i.news_finance##c.infl_exp_qual##i.edu_h $demo1 [pweight=weight], vce(cluster hh_id)
qui: margins news_finance, dydx(int_exp_qual) predict(outcome(3)) by(edu_h)
marginsplot, by(edu_h) level(90) ytitle("") xtitle("Financial news")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title(" ") 
graph save edu_h_intexp_news_finance, replace

*Monetary news

qui: oprobit cons_past cons_fut i.news_monetary##c.int_exp_qual##i.edu_h i.news_monetary##c.infl_exp_qual##i.edu_h $demo1 [pweight=weight], vce(cluster hh_id)
qui: margins news_monetary, dydx(infl_exp_qual) predict(outcome(3)) by(edu_h)
marginsplot, by(edu_h) level(90) ytitle("") xtitle("Monetary news")  graphregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) plotregion(fcolor(white) ifcolor(white) lcolor(white) ilcolor(white)) title(" ") 
graph save edu_h_inflexp_news_mp, replace

********************************************************************************************************************************************************************************************************************************







